package thread

//等待与通知机制
//https://redspider.gitbook.io/concurrent/di-yi-pian-ji-chu-pian/5
class Wait {

    @Synchronized
    fun wait1() {
        println("wait1 start")
        (this as Object).wait()
        println("wait1 end")
    }

    @Synchronized
    fun notify1() {
        println("notify1 start")
        Thread.sleep(2000L)
        (this as Object).notify()
        println("notify1 end")
    }
}

fun main() {
    val wait = Wait()

    val thread = Thread {
        wait.wait1()
    }

    val thread1 = Thread {
        wait.notify1()
    }

    thread.start()
    Thread.sleep(1000L)
    thread1.start()
}